<template>
  <div class="settings">
    <van-nav-bar safe-area-inset-top placeholder :title="$t('AdvancedSetting')" left-arrow fixed @click-left="onClickLeft" />
    <van-pull-refresh v-model="isLoading" :pulling-text="$t('PullingText')" :loosing-text="$t('PullingText')" :success-text="$t('refreshSuccee')" @refresh="onRefresh">
      <van-collapse class="marginTop15" v-model="activeNames">
        <van-collapse-item :title="$t('Safety')" name="1">
          <safetyPTVue :deviceType="15" :safety="safety" :reg="61" :key="timer" @getFormData="setSafety"></safetyPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Grid')" name="2">
          <vacMaxPTVue :setName="$t('UnderVoltage_L2')" :setUntil="'V'" :setMin="'0.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMinValue" :reg="1" v-if="safety==1||safety==2||safety==9||safety==19||safety==20||safety==26||safety==28"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('OverVoltage_L2')" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMaxValue" :reg="2" v-if="safety==1||safety==2||safety==9||safety==19||safety==20||safety==24||safety==26||safety==28"></vacMaxPTVue>
          <facMaxPTVue :setName="$t('UnderFreq_L2')" :setUntil="'Hz'" :setMin="'40.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMinValue" :reg="3" v-if="safety==2||safety==9||safety==19||safety==26"></facMaxPTVue>
          <facMaxPTVue :setName="$t('OverFreq_L2')" :setUntil="'Hz'" :setMin="'40.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMaxValue" :reg="4" v-if="safety==2||safety==9||safety==19||safety==26"></facMaxPTVue>
          <vacMaxPTVue :setName="$t('Vac10MAvg')" :setUntil="'V'" :setMin="'150.0'" :setMax="'300.0'" :setValue.sync="LocalArr.Grid10MinAverageValue" :reg="5" v-if="safety==1||safety==2||safety==4||safety==9||safety==19||safety==24||safety==26"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('UnderVoltage_L1')" :setUntil="'V'" :setMin="'0.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMinSlowProtectValue" :reg="6" v-if="safety==1||safety==2||safety==4||safety==9||safety==19||safety==20||safety==24||safety==26||safety==28||safety==29"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('OverVoltage_L1')" :setUntil="'V'" :setMin="'100.0'" :setMax="'300.0'" :setValue.sync="LocalArr.VacMaxSlowProtectValue" :reg="7" v-if="safety==2||safety==4||safety==19||safety==20||safety==24||safety==26||safety==28||safety==29"></vacMaxPTVue>
          <facMaxPTVue :setName="$t('UnderFreq_L1')" :setUntil="'Hz'" :setMin="'40.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMinSlowProtectValue" :reg="8" v-if="safety==1||safety==2||safety==4||safety==9||safety==19||safety==20||safety==24||safety==26||safety==28||safety==29"></facMaxPTVue>
          <facMaxPTVue :setName="$t('OverFreq_L1')" :setUntil="'Hz'" :setMin="'40.00'" :setMax="'65.00'" :setValue.sync="LocalArr.FacMaxSlowProtectValue" :reg="9" v-if="safety==1||safety==2||safety==4||safety==9||safety==19||safety==20||safety==24||safety==26||safety==28||safety==29"></facMaxPTVue>
          <setWgraPTVue :setName="$t('SetWgra')" :setMin="'0.0500'" :setMax="'1.0000'" :setValue.sync="LocalArr.SetWgraValue" :reg="81" v-if="safety==2||safety==4||safety==9||safety==24||safety==26||safety==29"></setWgraPTVue>
          <pfLockInPointPTVue :setName="$t('ReConnectionTime')" :setUntil="'S'" :setMin="15" :setMax="600" :setValue.sync="LocalArr.ReconnectionTimeValue" :reg="18" v-if="safety!=0"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('CheckingTime')" :setUntil="'S'" :setMin="15" :setMax="1000" :setValue.sync="LocalArr.CheckingTimeValue" :reg="19" v-if="safety!=0&&safety!=6&&safety!=30&&safety!=31"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('Tuvp_L2')" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeVacMinFastAdjValue" :reg="10" v-if="safety==1||safety==9||safety==26"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('Tovp_L2')" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeVacMaxFastAdjValue" :reg="11" v-if="safety==1||safety==9||safety==24||safety==26"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('Tufp_L2')" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeFacMinFastAdjValue" :reg="12" v-if="safety==9||safety==26"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('Tofp_L2')" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeFacMaxFastAdjValue" :reg="13" v-if="safety==9||safety==26"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('Tuvp_L1')" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeVacMinSlowAdjValue" :reg="14" v-if="safety==1||safety==4||safety==9||safety==24||safety==26||safety==29"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('Tovp_L1')" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeVacMaxSlowAdjValue" :reg="15" v-if="safety==4||safety==24||safety==26||safety==29"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('Tufp_L1')" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeFacMinSlowAdjValue" :reg="16" v-if="safety==1||safety==4||safety==9||safety==24||safety==26||safety==29"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('Tofp_L1')" :setUntil="'Ms'" :setMin="1" :setMax="9999" :setValue.sync="LocalArr.TimeFacMaxSlowAdjValue" :reg="17" v-if="safety==1||safety==4||safety==9||safety==24||safety==26||safety==29"></pfLockInPointPTVue>
          <languagePTVue
            :setName="$t('OFPL_Curve')"
            :columns="OFPLCurveArr"
            :setValue="LocalArr.OFPLCurveCode"
            :reg="88"
            @getFormData="setOFPLCurve"
            v-if="safety==4||safety==9||safety==24||safety==26||safety==29"
          ></languagePTVue>
          <pfLockInPointPTVue :setName="$t('OFPL_Tstop')" :setUntil="'S'" :setMin="0" :setMax="600" :setValue.sync="LocalArr.OFPLTstopValue" :reg="89" v-if="isOFPLCurve&&(safety==4||safety==9||safety==24||safety==26||safety==29)"></pfLockInPointPTVue>
          <facMaxPTVue :setName="$t('OFPL_RemovePoint')" :setUntil="'Hz'" :setMin="'50.00'" :setMax="'52.00'" :setValue.sync="LocalArr.OFPLRemovePointValue" :reg="131" v-if="isOFPLCurve&&safety==9"></facMaxPTVue>
          <facMaxPTVue :setName="$t('OFPL_StartPoint')" :setUntil="'Hz'" :setMin="'50.20'" :setMax="'50.50'" :setValue.sync="LocalArr.ofplStartPointValue" :reg="90" v-if="safety==1||safety==2||safety==4||safety==9||safety==24||safety==26||safety==29"></facMaxPTVue>
          <pfLockInPointPTVue :setName="$t('OFPL_DropRate')" :setUntil="'%'" :setMin="2" :setMax="12" :setValue.sync="LocalArr.ofplSetRateValue" :reg="91" v-if="safety==1||safety==4||safety==9||safety==24||safety==26||safety==29"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('OFPL_DelayTime')" :setUntil="'Ms'" :setMin="0" :setMax="2000" :setValue.sync="LocalArr.ofplDelayTimeValue" :reg="92" v-if="safety==1||safety==4||safety==9||safety==24||safety==26||safety==29"></pfLockInPointPTVue>
          <facMaxPTVue :setName="$t('UFPL_StartPoint')" :setUntil="'Hz'" :setMin="'46.00'" :setMax="'49.80'" :setValue.sync="LocalArr.ufplStartPointValue" :reg="93" v-if="safety==1||safety==2||safety==4||safety==9||safety==24||safety==26||safety==29"></facMaxPTVue>
          <pfLockInPointPTVue :setName="$t('UFPL_DropRate')" :setUntil="'%'" :setMin="2" :setMax="12" :setValue.sync="LocalArr.ufplSetRateValue" :reg="94" v-if="safety==1||safety==4||safety==9||safety==24||safety==26||safety==29"></pfLockInPointPTVue>
          <freDroopDelayTimePTVue :setName="$t('UFPL_DelayTime')" :setUntil="'Ms'" :setMin="0" :setMax="2000" :setValue.sync="LocalArr.ufplDelayTimeValue" :reg="95" v-if="safety==1||safety==4||safety==9||safety==24||safety==26||safety==29"></freDroopDelayTimePTVue>
          <facMaxPTVue :setName="$t('UFPL_RemovePoint')" :setUntil="'Hz'" :setMin="'46.00'" :setMax="'50.00'" :setValue.sync="LocalArr.UFPLRemovePointValue" :reg="132" v-if="safety==9"></facMaxPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('ExportControl')" name="3">
          <pfLockInPointPTVue :setName="$t('UserValue')" :setUntil="'W'" :setMin="0" :setMax="60000" :setValue.sync="LocalArr.ExportLimitValue" :reg="48"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('MeterCTSettings')" name="4">
          <languagePTVue
            :setName="$t('ModeSelect')"
            :columns="meterArr"
            :setValue="LocalArr.MeterModeCode"
            :reg="109"
            @getFormData="setMeterMode"
          ></languagePTVue>
          <pfLockInPointPTVue :setName="$t('Meter1ID')" :setMin="1" :setMax="200" :setValue.sync="LocalArr.Meter1IDValue" :reg="110" v-if="isMeter"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('Meter2ID')" :setMin="1" :setMax="200" :setValue.sync="LocalArr.Meter2IDValue" :reg="111"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item title="Shadow Fix" name="5">
          <languagePTVue :columns="ShadowFixArr" :setValue="LocalArr.ShadowFixValue" :reg="106"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item title="Modbus" name="6">
          <languagePTVue :setName="'Braud Rate'" :columns="modbusArr" :setValue="LocalArr.ModbusValue" :reg="103"></languagePTVue>
          <pfLockInPointPTVue :setName="$t('Address')" :setMin="1" :setMax="255" :setValue.sync="LocalArr.ModbusAddressValue" :reg="102"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item title="Mate Box Setting" name="7">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.MateBoxValue" :reg="105"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('PowerFactor')" name="8" v-if="safety==1||safety==4||safety==9||safety==20||safety==24||safety==26||safety==29||safety==30||safety==31">
          <van-form @submit="powerfactorSubmit">
            <van-field :value="LocalArr.factMode" :label="$t('ModeSelect')" readonly clickable name="picker" input-align="right" @click="showPowerFact = true" />
            <van-popup v-model="showPowerFact" round position="bottom">
              <van-picker show-toolbar :columns="powerFactors" 
                @cancel="showPowerFact = false" 
                @confirm="factModeConfirm" 
                :confirm-button-text="$t('OK')"
                :cancel-button-text="$t('Cancel')" 
              />
            </van-popup>
            <van-field v-if="(factModeCode==1||factModeCode==2)&&(safety==1||safety==4||safety==9||safety==20||safety==24||safety==26||safety==29||safety==30||safety==31)" 
              v-model="LocalArr.P2Value" 
              :label="$t('PFValue')" 
              type="number" 
              show-error 
              name="validator" 
              input-align="right" 
              error-message-align="right" 
              clearable 
              :rules="[{ validator:fixedTwo1,message: `${$t('Range')}：0.80-1.00` }]" 
            />
            <van-field v-if="factModeCode==3&&(safety==4||safety==9||safety==24||safety==26||safety==29)"
              v-model="LocalArr.P3Value" 
              label="P1_PF"  
              type="number" 
              show-error 
              name="validator" 
              input-align="right" 
              error-message-align="right" 
              clearable 
              :rules="[{ validator:fixedTwo1,message: `${$t('Range')}：0.80-1.00` }]" 
            />
            <van-field v-if="factModeCode==3&&(safety==4||safety==9||safety==24||safety==26||safety==29)"
              v-model="LocalArr.P4Value" 
              label="P2_PF"
              type="number" 
              show-error 
              name="validator" 
              input-align="right" 
              error-message-align="right" 
              clearable 
              :rules="[{ validator:fixedTwo1,message: `${$t('Range')}：0.80-1.00` }]" 
            />
            <van-field v-if="factModeCode==3&&(safety==4||safety==9||safety==24||safety==26||safety==29)"
              v-model="LocalArr.P5Value" 
              label="P3_PF" 
              type="number" 
              show-error 
              name="validator" 
              input-align="right" 
              error-message-align="right" 
              clearable 
              :rules="[{ validator:fixedTwo1,message: `${$t('Range')}：0.80-1.00` }]" 
            />
            <van-field v-if="factModeCode==3&&(safety==4||safety==9||safety==24||safety==26||safety==29)"
              v-model="LocalArr.P6Value" 
              label="P4_PF" 
              type="number" 
              show-error 
              name="validator" 
              input-align="right" 
              error-message-align="right" 
              clearable 
              :rules="[{ validator:fixedTwo1,message: `${$t('Range')}：0.80-1.00` }]" 
            />
            <div class="factorBtnBox">
              <van-button block round>{{$t('Save')}}</van-button>
            </div>
          </van-form>
          <pfLockInPointPTVue :setName="'Power1'" :setUntil="'%'" :setMin="0" :setMax="100" :setValue.sync="LocalArr.Power1Value" :reg="121" v-if="isPFP&&safety==100"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="'Power2'" :setUntil="'%'" :setMin="0" :setMax="100" :setValue.sync="LocalArr.Power2Value" :reg="122" v-if="isPFP&&safety==100"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="'Power3'" :setUntil="'%'" :setMin="0" :setMax="100" :setValue.sync="LocalArr.Power3Value" :reg="123" v-if="isPFP&&safety==100"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="'Power4'" :setUntil="'%'" :setMin="0" :setMax="100" :setValue.sync="LocalArr.Power4Value" :reg="124" v-if="isPFP&&safety==100"></pfLockInPointPTVue>
          <vacMaxPTVue :setName="'PfLockInPoint'" :setUntil="'V'" :setMin="'207.0'" :setMax="'253.0'" :setValue.sync="LocalArr.PfLockInPointValue" :reg="68" v-if="isPFP&&safety==9"></vacMaxPTVue>
          <vacMaxPTVue :setName="'PfLockOutPoint'" :setUntil="'V'" :setMin="'207.0'" :setMax="'253.0'" :setValue.sync="LocalArr.PfLockOutPointValue" :reg="69" v-if="isPFP&&safety==9"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('QuResponseV1')" :setUntil="'V'" :setMin="'207.0'" :setMax="'253.0'" :setValue.sync="LocalArr.wQuVrateUpValue" :reg="72" v-if="isQu&&(safety==4||safety==9||safety==24||safety==26||safety==29)"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('QuResponseV2')" :setUntil="'V'" :setMin="'207.0'" :setMax="'253.0'" :setValue.sync="LocalArr.wQuVrateLowValue" :reg="73" v-if="isQu&&(safety==4||safety==9||safety==24||safety==26||safety==29)"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('QuResponseV3')" :setUntil="'V'" :setMin="'207.0'" :setMax="'253.0'" :setValue.sync="LocalArr.QuResponseV3Value" :reg="74" v-if="isQu&&(safety==4||safety==9||safety==24||safety==26||safety==29)"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('QuResponseV4')" :setUntil="'V'" :setMin="'207.0'" :setMax="'253.0'" :setValue.sync="LocalArr.QuResponseV4Value" :reg="75" v-if="isQu&&(safety==4||safety==9||safety==24||safety==26||safety==29)"></vacMaxPTVue>
          <pfLockInPointPTVue :setName="$t('VoltRatio1')" :setUntil="'%'" :setMin="0" :setMax="60" :setValue.sync="LocalArr.SetQurangeV1Value" :reg="70" v-if="isQu&&safety==100"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('VoltRatio4')" :setUntil="'%'" :setMin="0" :setMax="60" :setValue.sync="LocalArr.SetQurangeV4Value" :reg="71" v-if="isQu&&safety==100"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="'3Tau'" :setUntil="'S'" :setMin="6" :setMax="180" :setValue.sync="LocalArr.tauValue" :reg="87" v-if="isPFP&&safety==1"></pfLockInPointPTVue>
          <pfLockInPointPT2Vue :setName="$t('bQpower_set')" :setMin="bQpowerMin" :setMax="bQpowerMax" :setValue.sync="LocalArr.bQpower_setValue" :reg="76" v-if="isQSet&&(safety==1||safety==4||safety==9||safety==24||safety==26||safety==29)"></pfLockInPointPT2Vue>
          <facMaxPT2Vue :setName="'K'" :setMin="-100" :setMax="100" :setValue.sync="LocalArr.KValue" :reg="125" v-if="isQu&&safety==9"></facMaxPT2Vue>
          <pfLockInPointPTVue :setName="$t('3Tau')" :setUntil="'S'" :setMin="6" :setMax="180" :setValue.sync="LocalArr.Qu3TauValue" :reg="126" v-if="isQu&&(safety==4||safety==9||safety==24||safety==26||safety==29)"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('QuDelayTimer')" :setUntil="'S'" :setMin="0" :setMax="30" :setValue.sync="LocalArr.QuDelayTimerValue" :reg="127" v-if="isQu&&safety==9"></pfLockInPointPTVue>
          <languagePTVue
            :setName="$t('QuLockEn')"
            :columns="toggleArr"
            :setValue="LocalArr.QuLockEnCode"
            :reg="128"
            @getFormData="setQuLockEn"
            v-if="isQu&&(safety==4||safety==9||safety==26)"
          ></languagePTVue>
          <pfLockInPointPTVue :setName="$t('QuLockIn')" :setUntil="'%'" :setMin="0" :setMax="20" :setValue.sync="LocalArr.QuLockInValue" :reg="129" v-if="isQu&&isQuLockEn&&(safety==4||safety==9||safety==26)"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('QuLockOut')" :setUntil="'%'" :setMin="0" :setMax="20" :setValue.sync="LocalArr.QuLockOutValue" :reg="130" v-if="isQu&&isQuLockEn&&(safety==4||safety==9||safety==26)"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('puFunction')" name="9" v-if="safety==4||safety==24||safety==26||safety==29">
          <languagePTVue
            :setName="$t('puFunction')"
            :columns="toggleArr"
            :setValue="LocalArr.puFunctionEnableCode"
            :reg="82"
            @getFormData="setPuFunction"
          ></languagePTVue>
          <vacMaxPTVue :setName="$t('SetV1')" :setUntil="'V'" :setMin="'207.0'" :setMax="'276.0'" :setValue.sync="LocalArr.SetV1Value" :reg="83" v-if="isPu&&(safety==24||safety==26)"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('SetV2')" :setUntil="'V'" :setMin="'207.0'" :setMax="'276.0'" :setValue.sync="LocalArr.SetV2Value" :reg="84" v-if="isPu&&(safety==24||safety==26)"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('SetV3')" :setUntil="'V'" :setMin="'207.0'" :setMax="'276.0'" :setValue.sync="LocalArr.SetV3Value" :reg="85" v-if="isPu&&(safety==24||safety==26)"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('SetV4')" :setUntil="'V'" :setMin="'207.0'" :setMax="'276.0'" :setValue.sync="LocalArr.SetV4Value" :reg="86" v-if="isPu&&(safety==26)"></vacMaxPTVue>
          <pfLockInPointPTVue :setName="$t('3Tau')" :setUntil="'S'" :setMin="6" :setMax="180" :setValue.sync="LocalArr.Pu3TauValue" :reg="137" v-if="isPu&&(safety==4||safety==24||safety==26||safety==29)"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('H/LVRTFunction')" name="10">
          <languagePTVue
            :setName="$t('H/LVRTFunction')"
            :columns="toggleArr"
            :setValue="LocalArr.HLVRTFunctionValue"
            :reg="100"
            @getFormData="setHLVRTFunction"
          ></languagePTVue>
          <pfLockInPointPTVue :setName="$t('VacUpper')" :setUntil="'V'" :setMin="230" :setMax="288" :setValue.sync="LocalArr.HLVacUpperValue" :reg="133" v-if="isHLVRTFunction"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="$t('VacLower')" :setUntil="'V'" :setMin="46" :setMax="240" :setValue.sync="LocalArr.HLVacLowerValue" :reg="134" v-if="isHLVRTFunction"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('ActivePowerLimit')" name="11">
          <pfLockInPointPTVue :setName="$t('ActivePowerLimit')" :setUntil="'%'" :setMin="0" :setMax="100" :setValue.sync="LocalArr.powerLimitValue" :reg="101"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item title="DRM Function" name="12" v-if="safety==2||safety==19">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.DRMFunctionValue" :reg="97"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item title="Main Breaker Limit (A)" name="13">
          <pfLockInPointPTVue :setMin="32" :setMax="100" :setValue.sync="LocalArr.MainBreakerLimitValue" :reg="112"></pfLockInPointPTVue>
        </van-collapse-item>
        <div v-if="isBatHeatSurport">
          <van-collapse-item :title="'Battery Heating'" name="14">
          <languagePTVue :setName="'Battery Heating'" :columns="toggleArr" :setValue="LocalArr.BatteryHeatingValue" :reg="116" @getFormData="setBatteryHeating"></languagePTVue>
          <div v-if="isBatteryHeating">
            <van-divider>Heating Period 1</van-divider>
            <chargeTimePTVue :setName="$t('StartTime')" :setValue="LocalArr.HeatingStartTime1" :reg="117"></chargeTimePTVue>
            <chargeTimePTVue :setName="$t('EndTime')" :setValue="LocalArr.HeatingEndTime1" :reg="118"></chargeTimePTVue>
            <van-divider>Heating Period 2</van-divider>
            <chargeTimePTVue :setName="$t('StartTime')" :setValue="LocalArr.HeatingStartTime2" :reg="119"></chargeTimePTVue>
            <chargeTimePTVue :setName="$t('EndTime')" :setValue="LocalArr.HeatingEndTime2" :reg="120"></chargeTimePTVue>
          </div>
        </van-collapse-item>
        </div>
        <van-collapse-item title="Off-grid setting" name="15">
          <languagePTVue :setName="$t('Frequency')" :setUntil="'Hz'" :columns="OffGridFreArr" :setValue="LocalArr.OffGridFreValue" :reg="135"></languagePTVue>
          <pfLockInPointPTVue :setName="$t('MinSoc')" :setUntil="'%'" :setMin="10" :setMax="25" :setValue.sync="LocalArr.OffGridMinSocValue" :reg="136"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Reset')" name="16">
          <resetINVEnergyPTVue :setName="$t('ClearInverterHistory')" :reg="27"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('ResetErrorLogs')" :reg="22"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('RestMeterCT1')" :reg="24"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('RestMeterCT2')" :reg="25"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('Restorefactorysettings')" :reg="23"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('ClearOverloadFault')" :reg="21"></resetINVEnergyPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('NewPassword')" name="17">
          <newPasswordPTVue :setValue.sync="LocalArr.NewPasswordValue" :reg="80"></newPasswordPTVue>
        </van-collapse-item>
        <van-collapse-item title="Self Test" name="18" v-if="safety==9">
          <van-cell title="Self Test Start" is-link @click="goSelftTest(1)" />
          <van-cell title="Self Test Results" is-link @click="goSelftTest(2)" />
        </van-collapse-item>
      </van-collapse>
    </van-pull-refresh>
  </div>
</template>

<script>
import safetyPTVue from '../../../components/Safety/BDSafetyPT'
import pfLockInPointPTVue from '../../../components/PfLockInPoint/BDPfLockInPointPT'
import vacMaxPTVue from '../../../components/VacMax/BDVacMaxPT'
import facMaxPTVue from '../../../components/FacMax/BDFacMaxPT'
import freDroopDelayTimePTVue from '../../../components/FreDroopDelayTime/BDFreDroopDelayTimePT'
import timeVacMinFastAdjPTVue from '../../../components/TimeVacMinFastAdj/BDTimeVacMinFastAdjPT'
import languagePTVue from '../../../components/Language/BDLanguagePT'
import resetINVEnergyPTVue from '../../../components/ResetINVEnergy/BDResetINVEnergyPT'
import newPasswordPTVue from '../../../components/NewPassword/BDNewPasswordPT'
import setWgraPTVue from '../../../components/SetWgra/BDSetWgra'
import chargeTimePTVue from '../../../components/ChargeTime/BDChargeTimePT';
import languagePT2Vue from '../../../components/Language/BDLanguage2PT';
import pfLockInPointPT2Vue from '../../../components/PfLockInPoint/BDPfLockInPoint2PT'
import facMaxPT2Vue from '../../../components/FacMax/BDFacMax2PT'

export default {
  components:{
    safetyPTVue,
    pfLockInPointPTVue,
    vacMaxPTVue,
    facMaxPTVue,
    freDroopDelayTimePTVue,
    timeVacMinFastAdjPTVue,
    languagePTVue,
    resetINVEnergyPTVue,
    newPasswordPTVue,
    setWgraPTVue,
    chargeTimePTVue,
    languagePT2Vue,
    pfLockInPointPT2Vue,
    facMaxPT2Vue
  },
  data(){
    return {
      isLoading:false,
      timer:'',
      activeNames:[],
      safety:sessionStorage.getItem('safety'),
      meterArr:['Meter','CT'],
      isMeter:false,
      toggleArr:[this.$t('Disable'),this.$t('Enable')],
      modbusArr:['115200','57600','56000','38400','19200','14400','9600'],
      showPowerFact:false,
      factorArr:[{text:this.$t('Off'),code:0},{text:this.$t('OverExcited1'),code:1},{text:this.$t('UnderExcited1'),code:2},{text:this.$t('PF(P)'),code:3},{text:this.$t('Q(u)'),code:4},{text:this.$t('Q-Set'),code:5}],
      powerFactors:[],
      factModeCode:'',
      isPFP:true,
      isQu:true,
      isQSet:true,
      bQpowerMin:'',
      bQpowerMax:'',
      isPu:false,
      isBatHeatSurport:false,
      isBatteryHeating:false,
      OFPLCurveArr:[this.$t('Symmetry'),this.$t('Asymmetry')],
      isOFPLCurve:false,
      ShadowFixArr:[this.$t('Off'),this.$t('low'),this.$t('Middle'),this.$t('High')],
      isQuLockEn:false,
      isHLVRTFunction:false,
      OffGridFreArr:['50','60'],
      LocalArr:{
        VacMinValue:'',
        VacMaxValue:'',
        FacMinValue:'',
        FacMaxValue:'',
        Grid10MinAverageValue:'',
        VacMinSlowProtectValue:'',
        VacMaxSlowProtectValue:'',
        FacMinSlowProtectValue:'',
        FacMaxSlowProtectValue:'',
        SetWgraValue:'',
        ReconnectionTimeValue:'',
        CheckingTimeValue:'',
        TimeVacMinFastAdjValue:'',
        TimeVacMaxFastAdjValue:'',
        TimeFacMinFastAdjValue:'',
        TimeFacMaxFastAdjValue:'',
        TimeVacMinSlowAdjValue:'',
        TimeVacMaxSlowAdjValue:'',
        TimeFacMinSlowAdjValue:'',
        TimeFacMaxSlowAdjValue:'',
        OFPLCurveCode:'',
        OFPLTstopValue:'',
        OFPLRemovePointValue:'',
        ofplStartPointValue:'',
        ofplSetRateValue:'',
        ofplDelayTimeValue:'',
        ufplStartPointValue:'',
        ufplSetRateValue:'',
        ufplDelayTimeValue:'',
        UFPLRemovePointValue:'',
        ExportLimitValue:'',
        MeterModeCode:'',
        Meter1IDValue:'',
        Meter2IDValue:'',
        ShadowFixValue:'',
        ModbusValue:'',
        ModbusAddressValue:'',
        MateBoxValue:'',
        factMode:'',
        P2Value:'',
        P3Value:'',
        P4Value:'',
        P5Value:'',
        P6Value:'',
        Power1Value:'',
        Power2Value:'',
        Power3Value:'',
        Power4Value:'',
        PfLockInPointValue:'',
        PfLockOutPointValue:'',
        wQuVrateUpValue:'',
        wQuVrateLowValue:'',
        QuResponseV3Value:'',
        QuResponseV4Value:'',
        SetQurangeV1Value:'',
        SetQurangeV4Value:'',
        tauValue:'',
        bQpower_setValue:'',
        KValue:'',
        Qu3TauValue:'',
        QuDelayTimerValue:'',
        QuLockEnCode:'',
        QuLockInValue:'',
        QuLockOutValue:'',
        puFunctionEnableCode:'',
        SetV1Value:'',
        SetV2Value:'',
        SetV3Value:'',
        SetV4Value:'',
        Pu3TauValue:'',
        HLVRTFunctionValue:'',
        HLVacUpperValue:'',
        HLVacLowerValue:'',
        powerLimitValue:'',
        DRMFunctionValue:'',
        MainBreakerLimitValue:'',
        BatteryHeatingValue:'',
        HeatingStartTime1:'',
        HeatingEndTime1:'',
        HeatingStartTime2:'',
        HeatingEndTime2:'',
        OffGridFreValue:'',
        OffGridMinSocValue:'',
        NewPasswordValue:''
      }
    }
  },
  methods: {
    onClickLeft(){
      this.$router.push({path:'/bdx1hybridg4setlist'});
    },
    goSelftTest(num){
      sessionStorage.setItem('setFrom','/bdx1hybridg4advanced');
      if(num==1){
        this.$router.push({path:'/bdteststart'});
      }else{
        this.$router.push({path:'/bdtestresult'});
      }
    },
    factModeConfirm(value,i){
      this.showPowerFact=false;
      this.LocalArr.factMode=value.text;
      this.factModeCode=value.code;
    },
    fixedTwo1(val){
      return this.comm.fixedTwo(val,0.8,1);
    },
    async getData(){
      this.comm.loadingShow();
      let datas=await this.SETAPI.LocalIn({'optType':'ReadSetData','pwd':sessionStorage.getItem('bdPwd')});
      if(datas!=null||datas!=undefined){
        let dataArr = datas;
        this.safety=dataArr[60];
        sessionStorage.setItem('safety',this.safety);
        this.LocalArr.VacMinValue=dataArr[0]/10;
        this.LocalArr.VacMaxValue=dataArr[1]/10;
        this.LocalArr.FacMinValue=dataArr[2]/100;
        this.LocalArr.FacMaxValue=dataArr[3]/100;
        this.LocalArr.Grid10MinAverageValue=dataArr[4]/10;
        this.LocalArr.VacMinSlowProtectValue=dataArr[5]/10;
        this.LocalArr.VacMaxSlowProtectValue=dataArr[6]/10;
        this.LocalArr.FacMinSlowProtectValue=dataArr[7]/100;
        this.LocalArr.FacMaxSlowProtectValue=dataArr[8]/100;
        this.LocalArr.SetWgraValue=dataArr[80]/10000;
        this.LocalArr.ReconnectionTimeValue=dataArr[17];
        this.LocalArr.CheckingTimeValue=dataArr[18];
        this.LocalArr.TimeVacMinFastAdjValue=dataArr[9];
        this.LocalArr.TimeVacMaxFastAdjValue=dataArr[10];
        this.LocalArr.TimeFacMinFastAdjValue=dataArr[11];
        this.LocalArr.TimeFacMaxFastAdjValue=dataArr[12];
        this.LocalArr.TimeVacMinSlowAdjValue=dataArr[13];
        this.LocalArr.TimeVacMaxSlowAdjValue=dataArr[14];
        this.LocalArr.TimeFacMinSlowAdjValue=dataArr[15];
        this.LocalArr.TimeFacMaxSlowAdjValue=dataArr[16];
        this.LocalArr.OFPLCurveCode=dataArr[87];
        /*判断用户的选择*/
        if(this.LocalArr.OFPLCurveCode==0){
          this.isOFPLCurve=false;
        }else{
          this.isOFPLCurve=true;
        }
        this.LocalArr.OFPLTstopValue=dataArr[88];
        this.LocalArr.OFPLRemovePointValue=dataArr[130]/100;
        this.LocalArr.ofplStartPointValue=dataArr[92]/100;
        this.LocalArr.ofplSetRateValue=dataArr[93];
        this.LocalArr.ofplDelayTimeValue=dataArr[94];
        this.LocalArr.ufplStartPointValue=dataArr[89]/100;
        this.LocalArr.ufplSetRateValue=dataArr[90];
        this.LocalArr.ufplDelayTimeValue=dataArr[91];
        this.LocalArr.UFPLRemovePointValue=dataArr[131]/100;
        this.LocalArr.ExportLimitValue=dataArr[47];
        this.LocalArr.MeterModeCode=dataArr[108];
        /*判断用户的选择*/
        if(this.LocalArr.MeterModeCode==0){
          this.isMeter=true;
        }else{
          this.isMeter=false;
        }
        this.LocalArr.Meter1IDValue=dataArr[109];
        this.LocalArr.Meter2IDValue=dataArr[110];
        this.LocalArr.ShadowFixValue=dataArr[105];
        this.LocalArr.ModbusValue=dataArr[102];
        this.LocalArr.ModbusAddressValue=dataArr[101];
        this.LocalArr.MateBoxValue=dataArr[104];
        this.factModeCode=dataArr[61];
        this.LocalArr.factMode=this.factorArr[this.factModeCode].text;
        /*判断用户的选择*/
        if(dataArr[61]==3){
          this.isPFP=true;
        }else{
          this.isPFP=false;
        }
        if(dataArr[61]==4){
          this.isQu=true;
        }else{
          this.isQu=false;
        }
        if(dataArr[61]==5){
          this.isQSet=true;
        }else{
          this.isQSet=false;
        }
        this.LocalArr.P2Value=dataArr[62]/100;
        this.LocalArr.P3Value=dataArr[63]/100;
        this.LocalArr.P4Value=dataArr[64]/100;
        this.LocalArr.P5Value=dataArr[65]/100;
        this.LocalArr.P6Value=dataArr[66]/100;
        this.LocalArr.Power1Value=dataArr[120];
        this.LocalArr.Power2Value=dataArr[121];
        this.LocalArr.Power3Value=dataArr[122];
        this.LocalArr.Power4Value=dataArr[123];
        this.LocalArr.PfLockInPointValue=dataArr[67]/10;
        this.LocalArr.PfLockOutPointValue=dataArr[68]/10;
        this.LocalArr.wQuVrateUpValue=dataArr[71]/10;
        this.LocalArr.wQuVrateLowValue=dataArr[72]/10;
        this.LocalArr.QuResponseV3Value=dataArr[73]/10;
        this.LocalArr.QuResponseV4Value=dataArr[74]/10;
        this.LocalArr.SetQurangeV1Value=dataArr[69];
        this.LocalArr.SetQurangeV4Value=dataArr[70];
        this.LocalArr.tauValue=dataArr[86];
        this.LocalArr.bQpower_setValue=this.comm.bit16(0,dataArr[75]);
        this.bQpowerMin=this.comm.bit16(0,dataArr[77]);
        this.bQpowerMax=this.comm.bit16(0,dataArr[76]);
        this.LocalArr.KValue=dataArr[124]/100;
        this.LocalArr.Qu3TauValue=dataArr[125];
        this.LocalArr.QuDelayTimerValue=dataArr[126];
        this.LocalArr.QuLockEnCode=dataArr[127];
        /*判断用户的选择*/
        if(this.LocalArr.QuLockEnCode==1){
          this.isQuLockEn=true;
        }else{
          this.isQuLockEn=false;
        }
        this.LocalArr.QuLockInValue=dataArr[128];
        this.LocalArr.QuLockOutValue=dataArr[129];
        this.LocalArr.puFunctionEnableCode=dataArr[81];
        /*判断用户的选择*/
        if(this.LocalArr.puFunctionEnableCode==1){
          this.isPu=true;
        }else{
          this.isPu=false;
        }
        this.LocalArr.SetV1Value=dataArr[82]/10;
        this.LocalArr.SetV2Value=dataArr[83]/10;
        this.LocalArr.SetV3Value=dataArr[84]/10;
        this.LocalArr.SetV4Value=dataArr[85]/10;
        this.LocalArr.Pu3TauValue=dataArr[136];
        this.LocalArr.HLVRTFunctionValue=dataArr[99];
        /*判断用户的选择*/
        if(this.LocalArr.HLVRTFunctionValue==1){
          this.isHLVRTFunction=true;
        }else{
          this.isHLVRTFunction=false;
        }
        this.LocalArr.HLVacUpperValue=dataArr[132];
        this.LocalArr.HLVacLowerValue=dataArr[133];
        this.LocalArr.powerLimitValue=dataArr[100];
        this.LocalArr.DRMFunctionValue=dataArr[96];
        this.LocalArr.MainBreakerLimitValue=dataArr[111];
        if(dataArr[114]==1){
          this.isBatHeatSurport=true;
        }else{
          this.isBatHeatSurport=false;
        }
        this.LocalArr.BatteryHeatingValue=dataArr[115];
        let HeatingStartHour1=this.comm.bit8low(1,dataArr[116]);
        let HeatingStartMinute1=this.comm.bit8high(1,dataArr[116]);
        HeatingStartHour1=HeatingStartHour1>=10?HeatingStartHour1:"0"+HeatingStartHour1;
        HeatingStartMinute1=HeatingStartMinute1>=10?HeatingStartMinute1:"0"+HeatingStartMinute1;
        this.LocalArr.HeatingStartTime1=`${HeatingStartHour1}:${HeatingStartMinute1}`;

        let HeatingEndHour1=this.comm.bit8low(1,dataArr[117]);
        let HeatingEndMinute1=this.comm.bit8high(1,dataArr[117]);
        HeatingEndHour1=HeatingEndHour1>=10?HeatingEndHour1:"0"+HeatingEndHour1;
        HeatingEndMinute1=HeatingEndMinute1>=10?HeatingEndMinute1:"0"+HeatingEndMinute1;
        this.LocalArr.HeatingEndTime1=`${HeatingEndHour1}:${HeatingEndMinute1}`;

        let HeatingStartHour2=this.comm.bit8low(1,dataArr[118]);
        let HeatingStartMinute2=this.comm.bit8high(1,dataArr[118]);
        HeatingStartHour2=HeatingStartHour2>=10?HeatingStartHour2:"0"+HeatingStartHour2;
        HeatingStartMinute2=HeatingStartMinute2>=10?HeatingStartMinute2:"0"+HeatingStartMinute2;
        this.LocalArr.HeatingStartTime2=`${HeatingStartHour2}:${HeatingStartMinute2}`;

        let HeatingEndHour2=this.comm.bit8low(1,dataArr[119]);
        let HeatingEndMinute2=this.comm.bit8high(1,dataArr[119]);
        HeatingEndHour2=HeatingEndHour2>=10?HeatingEndHour2:"0"+HeatingEndHour2;
        HeatingEndMinute2=HeatingEndMinute2>=10?HeatingEndMinute2:"0"+HeatingEndMinute2;
        this.LocalArr.HeatingEndTime2=`${HeatingEndHour2}:${HeatingEndMinute2}`;

        this.LocalArr.OffGridFreValue=dataArr[134];
        this.LocalArr.OffGridMinSocValue=dataArr[135];
        this.LocalArr.NewPasswordValue=this.comm.showPwd(dataArr[79]);
      }else{
        this.comm.tipsShow('InvNoResponse');
      }
    },
    //获取powerfactor列表
    getPowerFactory(){
      if(this.safety==20||this.safety==30||this.safety==31){
        this.powerFactors=[{text:this.$t('Off'),code:0},{text:this.$t('OverExcited1'),code:1},{text:this.$t('UnderExcited1'),code:2}];
      }else{
        this.powerFactors=[{text:this.$t('Off'),code:0},{text:this.$t('OverExcited1'),code:1},{text:this.$t('UnderExcited1'),code:2},{text:this.$t('PF(P)'),code:3},{text:this.$t('Q(u)'),code:4},{text:this.$t('Q-Set'),code:5}];
      }
    },
    //设置安规
    setSafety(data){
      if(data=='success'){
        this.safety=sessionStorage.getItem('safety');
        this.getPowerFactory();
      }
    },
    //设置OFPL_Curve
    setOFPLCurve(data){
      if (data == 1) {
        this.isOFPLCurve = true;
      } else {
        this.isOFPLCurve = false;
      }
    },
    //设置MeterMode
    setMeterMode(data){
      /*判断用户的选择*/
      if(data==0){
        this.isMeter=true;
      }else{
        this.isMeter=false;
      }
    },
    //设置powerfactor
    async powerfactorSubmit(){
      //处理数据
      let factorData_new={};
      factorData_new.P1Value=this.factModeCode;
      if(this.LocalArr.P2Value!=null&&this.LocalArr.P2Value!=undefined){
        factorData_new.P2Value=this.comm.mulFunction(this.LocalArr.P2Value,100);
      }
      if(this.LocalArr.P3Value!=null&&this.LocalArr.P3Value!=undefined){
        factorData_new.P3Value=this.comm.mulFunction(this.LocalArr.P3Value,100);
      }
      if(this.LocalArr.P4Value!=null&&this.LocalArr.P4Value!=undefined){
        factorData_new.P4Value=this.comm.mulFunction(this.LocalArr.P4Value,100);
      }
      if(this.LocalArr.P5Value!=null&&this.LocalArr.P5Value!=undefined){
        factorData_new.P5Value=this.comm.mulFunction(this.LocalArr.P5Value,100);
      }
      if(this.LocalArr.P6Value!=null&&this.LocalArr.P6Value!=undefined){
        factorData_new.P6Value=this.comm.mulFunction(this.LocalArr.P6Value,100);
      }
      let Datas={
        'num':6,
        'Data':[
          {'reg':62,'val':factorData_new.P1Value+''},
          {'reg':63,'val':factorData_new.P2Value+''},
          {'reg':64,'val':factorData_new.P3Value+''},
          {'reg':65,'val':factorData_new.P4Value+''},
          {'reg':66,'val':factorData_new.P5Value+''},
          {'reg':67,'val':factorData_new.P6Value+''}
        ]
      };
      let params={
        'optType':"setReg",
        'Data':JSON.stringify(Datas),
        'pwd':sessionStorage.getItem('bdPwd')
      };
      this.comm.loadingShow();
      let data = await this.SETAPI.LocalIn(params);
      let newdata=data.substring(0,1);
      if (newdata == "Y") {
        this.comm.toastSuccess();
        /*判断用户的选择*/
        if(this.factModeCode==3){
          this.isPFP=true;
        }else{
          this.isPFP=false;
        }
        if(this.factModeCode==4){
          this.isQu=true;
        }else{
          this.isQu=false;
        }
        if(this.factModeCode==5){
          this.isQSet=true;
        }else{
          this.isQSet=false;
        }
      } else {
        this.comm.toastFail();
      }
    },
    //设置QuLockEn
    setQuLockEn(data){
      if (data == 1) {
        this.isQuLockEn = true;
      } else {
        this.isQuLockEn = false;
      }
    },
    //设置PU Function
    setPuFunction(data){
      if (data == 1) {
        this.isPu = true;
      } else {
        this.isPu = false;
      }
    },
    //设置HLVRTFunction
    setHLVRTFunction(data){
      if (data == 1) {
        this.isHLVRTFunction = true;
      } else {
        this.isHLVRTFunction = false;
      }
    },
    //设置BatteryHeating
    setBatteryHeating(data){
      if (data == 1) {
        this.isBatteryHeating = true;
      } else {
        this.isBatteryHeating = false;
      }
    },
    onRefresh(){
      this.isLoading = false;
      this.timer=new Date().getTime();
      for(let i in this.LocalArr){
        this.LocalArr[i]='';
      }
      this.getData();
      this.getPowerFactory();
    }
  },
  mounted(){
    setTimeout(()=>{
      this.getData();
      this.getPowerFactory();
    },1000);
  }
}
</script>

<style scoped lang="less">

</style>
